//
//  WBBottomView.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/14.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBBottomView.h"
#import <Masonry.h>

@interface WBBottomView()

//转发按钮
@property (nonatomic , strong) UIButton *retweetButton;

//评论按钮
@property (nonatomic , strong) UIButton *commentButton;

//点赞按钮
@property (nonatomic , strong) UIButton *unlikeButton;

//两条线
@property (nonatomic , strong) UIImageView *line1;
@property (nonatomic , strong) UIImageView *line2;


@end

@implementation WBBottomView

- (UIImageView *)creatLineImageView
{
    UIImageView *line = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
    
    [self addSubview:line];
    
    return line;

}

#pragma mark - 重写属性的set方法
- (void)setStatusViewModel:(WBStatusViewModel *)statusViewModel
{
    _statusViewModel = statusViewModel;
    
    //给控件赋值
    [self.retweetButton setTitle:statusViewModel.repostsStr forState:UIControlStateNormal];
    [self.commentButton setTitle:statusViewModel.commentsStr forState:UIControlStateNormal];
    [self.unlikeButton setTitle:statusViewModel.attitudesStr forState:UIControlStateNormal];

}

//方法 创建按钮 传给我图片名字 和按钮名字
- (UIButton *)creatButtonWithBackGroundImageName:(NSString *)imageName andTitle:(NSString *)title
{
    //创建Btn
    UIButton *btn = [[UIButton alloc] init];
    //设置按钮背景图片
    [btn setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background_highlighted"] forState:UIControlStateHighlighted];
    
    //设置 按钮图片
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    //设置文字
    [btn setTitle:title forState:UIControlStateNormal];
    //设置颜色
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    //设置文字大小
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    //添加到父控件中
    [self addSubview:btn];

    return btn;
}


- (instancetype)initWithFrame:(CGRect)frame
{
   if (self = [super initWithFrame:frame])
   {
       
       [self setupUI];
   
   }
    
    return self;

}

//设置UI
- (void)setupUI
{
    self.retweetButton = [self creatButtonWithBackGroundImageName:@"timeline_icon_retweet" andTitle:@"转发"];
    self.commentButton = [self creatButtonWithBackGroundImageName:@"timeline_icon_comment" andTitle:@"评论"];
    self.unlikeButton = [self creatButtonWithBackGroundImageName:@"timeline_icon_unlike" andTitle:@"赞"];
    self.line1 = [self creatLineImageView];
    self.line2 = [self creatLineImageView];
    
    //添加约束
    [self.retweetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.top.bottom.equalTo(self);
        make.width.mas_equalTo(self.commentButton);
        
    }];
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.leading.mas_equalTo(self.retweetButton.mas_trailing);
        
    }];
    [self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self);
        make.leading.mas_equalTo(self.retweetButton.mas_trailing);
        make.width.mas_equalTo(self.unlikeButton);
    }];
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.commentButton.mas_trailing);
        make.centerY.mas_equalTo(self);
    }];
    [self.unlikeButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.trailing.mas_equalTo(self);
        make.leading.mas_equalTo(self.commentButton.mas_trailing);
        
    }];

}

@end
